import { Body, Controller, Get, HttpCode, HttpStatus, ParseIntPipe, Post, Query, Render } from '@nestjs/common'

import { RankDTO } from './rank.dto'
import { RankService } from './rank.service'

@Controller('rank')
export class RankController {
  constructor(private readonly service: RankService) {}
  @Get()
  @Render('rank')
  render() {
    return {
      title: '排行版'
    }
  }

  @HttpCode(HttpStatus.OK)
  @Post('add')
  add(@Body() data: RankDTO) {
    return this.service.save(data)
  }

  @Get('list')
  @Render('rank/list')
  renderList(@Query('size', new ParseIntPipe({ optional: true })) size = 100) {
    return this.service.list(size)
  }
}
